export const getType = item => (Object.prototype.toString.call(item).slice(8, -1));

getType.isNumber = (item) => getType(item) === 'Number';
getType.isString = item => getType(item) === 'String';
getType.isArray = item => getType(item) === 'Array';
getType.isObject = item => getType(item) === 'Object';
getType.isBoolean = item => getType(item) === 'Boolean';
getType.isNull = item => getType(item) === 'Null';
getType.isUndefined = item => getType(item) === 'Undefined';
getType.isFunction = item => getType(item) === 'Function';
getType.isDate = item => getType(item) === 'Date';


function _copy() {
  if(arguments.length) {
    const list = Array.prototype.map.call(arguments, item => item);
    const curObj = list.shift();
    Object.keys(curObj).forEach(item=>{
      const val = curObj[item];
      if(val !== undefined)
        this[item] = (getType.isObject(val) && copy(this[item]||{},val)) ||
          (getType.isArray(val) && val.map(item => item)) ||
          val;
    });
    return _copy.apply(this, list);
  } else return this;
}
export function copy(){return _copy.apply({},arguments);}

export default {
  copy: copy,
  type: getType
};
